home *** CD-ROM | disk | FTP | other *** search
- /*----------------------------------------------------------------------------
-
- ldef.c
-
- This module contains the LDEF for NewsWatcher.
-
- Copyright © 1994-1995, Northwestern University.
-
- ----------------------------------------------------------------------------*/
-
- #include <string.h>
-
- #include "glob.h"
- #include "ldef.h"
- #include "header.h"
- #include "drawutil.h"
- #include "windutil.h"
- #include "memutil.h"
-
- static RGBColor gLightBlue = {0x9999, 0x9999, 0xFFFF}; /* light blue for filling triangles */
-
- static Rect gRect; /* cell rect */
- static FontInfo gFontInfo; /* font information */
- static TWindow **gInfo; /* window information */
- static short gIndex; /* index in group or subject array */
- static Handle gStrings; /* handle to strings */
- static short gH, gV; /* h and v coords for drawing */
- static Rect gEraseRect; /* rectangle erased and redrawn */
- static TSubject **gSubjectArray; /* handle to subject array */
- static TSubject gTheSubject; /* subject record to be drawn */
- static short gRow; /* row number of cell being drawn */
- static ListHandle gTheList; /* handle to list record */
- static short gRightEdge; /* right cell edge minus indentation */
-
-
-
- /* The following global variable is exported. */
-
- ListDefUPP gListDefFuncUPP = nil;
-
-
-
- /*----------------------------------------------------------------------------
- DrawFullOrNewGroupCell
-
- Draw a single cell in the full group list window or the new groups
- list window.
- ----------------------------------------------------------------------------*/
-
- static void DrawFullOrNewGroupCell (void)
- {
- TGroup **groupArray;
- Str255 str;
-
- groupArray = (**gInfo).groupArray;
- gEraseRect = gRect;
- EraseRect(&gEraseRect);
- strcpy((char*)str, *gStrings + (*groupArray)[gIndex].nameOffset);
- c2pstr((char*)str);
- TruncString(gRightEdge - gH, str, smTruncEnd);
- MoveTo(gH, gV);
- DrawString(str);
- }
-
-
-
- /*----------------------------------------------------------------------------
- DrawUserGroupCell
-
- Draw a single cell in a user group list window.
- ----------------------------------------------------------------------------*/
-
- static void DrawUserGroupCell (void)
- {
- TGroup **groupArray, theGroup;
- long numUnread;
- Str255 str;
- short h;
-
- groupArray = (**gInfo).groupArray;
- theGroup = (*groupArray)[gIndex];
- gEraseRect = gRect;
- if (theGroup.onlyRedrawCount) gEraseRect.right = gH + (**gInfo).numUnreadHCoord;
- EraseRect(&gEraseRect);
- numUnread = theGroup.numUnread;
- if (numUnread != 0) {
- if (numUnread > 9999) numUnread = 9999;
- NumToString(numUnread, str);
- MoveTo(gH + (**gInfo).numUnreadHCoord - StringWidth(str), gV);
- DrawString(str);
- }
- if (!theGroup.onlyRedrawCount) {
- strcpy((char*)str, *gStrings + theGroup.nameOffset);
- c2pstr((char*)str);
- h = gH + (**gInfo).groupNameHCoord;
- TruncString(gRightEdge - h, str, smTruncEnd);
- MoveTo(h, gV);
- DrawString(str);
- }
- }
-
-
-
- /*----------------------------------------------------------------------------
- DrawThreadHeadInfo
-
- Draw the thread head info for a thread head cell in a subject list
- window (the thread control and number of articles in the thread).
- ----------------------------------------------------------------------------*/
-
- static void DrawThreadHeadInfo (void)
- {
- PolyHandle poly;
- short th, tv;
- Str255 str;
- short threadLength;
-
- if (gTheSubject.threadLength == 1) {
- MoveTo(gH + (**gInfo).minusSignHCoord, gV);
- DrawChar('-');
- } else {
- if (gTheSubject.collapsed) {
- poly = (**gInfo).collapseTriangle;
- th = gH + ((**poly).polyBBox.right >> 1) + 1;
- tv = gRect.top + 1;
- } else {
- poly = (**gInfo).expandTriangle;
- th = gH + 1;
- tv = gRect.top + ((**poly).polyBBox.bottom >> 1) + 1;
- }
- OffsetPoly(poly, th, tv);
- if (gTheSubject.drawTriangleFilled) {
- FillPoly(poly, &qd.black);
- } else {
- FillColorPoly(poly, &gLightBlue, &qd.gray);
- }
- FramePoly(poly);
- OffsetPoly(poly, -th, -tv);
-
- if (!gTheSubject.onlyRedrawTriangle) {
- threadLength = gTheSubject.threadLength;
- if (threadLength > 99) threadLength = 99;
- NumToString(threadLength, str);
- MoveTo(gH + (**gInfo).threadCountHCoord - StringWidth(str), gV);
- DrawString(str);
- }
- }
- }
-
-
-
- /*----------------------------------------------------------------------------
- DrawCheckMark
-
- Draw the article read check mark in a cell in a subject list window.
- For collapsed thread head cells, the mark is drawn iff the entire
- thread has been read.
- ----------------------------------------------------------------------------*/
-
- static void DrawCheckMark (void)
- {
- Boolean read;
- short nextInThread;
- TextStyle savedStyle;
-
- if (gTheSubject.collapsed) {
- read = true;
- nextInThread = gIndex;
- while (true) {
- if (!(*gSubjectArray)[nextInThread].read) {
- read = false;
- break;
- }
- nextInThread =
- (*gSubjectArray)[nextInThread].nextInThread;
- if (nextInThread == -1) break;
- }
- } else {
- read = gTheSubject.read;
- }
- if (read) {
- GetPortTextStyle(&savedStyle);
- TextFont(systemFont);
- MoveTo(gH + (**gInfo).checkHCoord, gV);
- DrawChar(checkMark);
- SetPortTextStyle(&savedStyle);
- } else if (gTheSubject.incomplete) {
- MoveTo(gH + (**gInfo).checkHCoord, gV);
- DrawChar('<');
- } else if (gTheSubject.complete) {
- MoveTo(gH + (**gInfo).checkHCoord, gV);
- DrawChar('•');
- }
- }
-
-
-
- /*----------------------------------------------------------------------------
- DrawAuthorAndSubject
-
- Draw the author and subject in a cell in a subject list window.
- ----------------------------------------------------------------------------*/
-
- static void DrawAuthorAndSubject (void)
- {
- Str255 str;
- short h;
-
- if ((**gInfo).authorsShown && gTheSubject.authorOffset >= 0) {
- strcpy((char*)str, *gStrings + gTheSubject.authorOffset);
- FormatAuthorName((char*)str);
- c2pstr((char*)str);
- TruncString((**gInfo).authorWidth, str, smTruncEnd);
- MoveTo(gH + (**gInfo).authorHCoord, gV);
- DrawString(str);
- }
- strcpy((char*)str, *gStrings + gTheSubject.subjectOffset);
- c2pstr((char*)str);
- h = gH + (**gInfo).subjectHCoord;
- TruncString(gRightEdge - h, str, smTruncEnd);
- MoveTo(h, gV);
- DrawString(str);
- }
-
-
-
- /*----------------------------------------------------------------------------
- DrawSubjectCell
-
- Draw a single cell in a subject list window.
- ----------------------------------------------------------------------------*/
-
- static void DrawSubjectCell (void)
- {
- gSubjectArray = (**gInfo).subjectArray;
- gTheSubject = (*gSubjectArray)[gIndex];
- gEraseRect = gRect;
- if (gTheSubject.onlyRedrawTriangle) {
- gEraseRect.right = gH + gFontInfo.ascent + 2;
- } else if (gTheSubject.onlyRedrawCheck) {
- gEraseRect.left = gH + (**gInfo).checkHCoord;
- gEraseRect.right = gH + (**gInfo).authorHCoord;
- }
- EraseRect(&gEraseRect);
-
- if (gTheSubject.threadOrdinal == 1 && !gTheSubject.onlyRedrawCheck)
- DrawThreadHeadInfo();
-
- if (!gTheSubject.onlyRedrawTriangle)
- DrawCheckMark();
-
- if (!gTheSubject.onlyRedrawTriangle && !gTheSubject.onlyRedrawCheck)
- DrawAuthorAndSubject();
- }
-
-
-
- /*----------------------------------------------------------------------------
- HiliteCell
-
- Hilite the cell.
- ----------------------------------------------------------------------------*/
-
- static void HiliteCell (void)
- {
- short pnMode;
- Rect visible;
- Boolean hasColorQD;
- unsigned char hiliteMode;
-
- hasColorQD = HasColorQD();
- if ((**gTheList).lActive && ((WindowPeek)qd.thePort)->hilited) {
- if (hasColorQD) {
- hiliteMode = LMGetHiliteMode();
- BitClr(&hiliteMode, pHiliteBit);
- LMSetHiliteMode(hiliteMode);
- }
- InvertRect(&gEraseRect);
- } else {
- visible = (**gTheList).visible;
- pnMode = qd.thePort->pnMode;
- if (hasColorQD) PenMode(50 + pnMode);
- ClipRect(&gEraseRect);
- MoveTo(gRect.left + 3, gRect.top);
- LineTo(gRect.left + 3, gRect.bottom - 1);
- MoveTo(gRect.right - 4, gRect.top);
- LineTo(gRect.right - 4, gRect.bottom - 1);
- if (gRow == visible.top || (**gTheList).cellArray[gRow-1] >= 0) {
- MoveTo(gRect.left + 4, gRect.top);
- LineTo(gRect.right - 5, gRect.top);
- }
- if (gRow == visible.bottom - 1 || (**gTheList).cellArray[gRow+1] >= 0) {
- MoveTo(gRect.left + 4, gRect.bottom - 1);
- LineTo(gRect.right - 5, gRect.bottom - 1);
- }
- ClipRect(&gRect);
- PenMode(pnMode);
- }
- }
-
-
-
- /*----------------------------------------------------------------------------
- ListDefFunc
-
- This is the list definition function used for group and subject list
- windows. It is called by the stub code in the standalone LDEF 128 code
- resource.
- ----------------------------------------------------------------------------*/
-
- static pascal void ListDefFunc (short lMessage, Boolean lSelect, Rect *lRect, Cell lCell,
- short lDataOffset, short lDataLen, ListHandle lHandle)
- {
- char *cellDataPtr;
- TWindowKind kind;
- Boolean selected;
-
- if (lMessage != lDrawMsg && lMessage != lHiliteMsg) return;
-
- selected = ((**lHandle).cellArray)[lCell.v] < 0;
- gRect = *lRect;
- gRow = lCell.v;
- gTheList = lHandle;
- gRightEdge = gRect.right - (**lHandle).indent.h;
-
- if (lMessage == lHiliteMsg && (**gTheList).lActive &&
- ((WindowPeek)qd.thePort)->hilited)
- {
- gEraseRect = gRect;
- HiliteCell();
- return;
- }
-
- (**lHandle).port->txFace = 0;
- GetFontInfo(&gFontInfo);
- gH = lRect->left + (**lHandle).indent.h;
- gV = lRect->top + gFontInfo.ascent;
- gInfo = (TWindow**)GetWRefCon((WindowPtr)(**lHandle).port);
- kind = (**gInfo).kind;
- if (kind == kSubject) {
- gStrings = (**gInfo).strings;
- } else {
- gStrings = gGroupNames;
- }
- cellDataPtr = *(**lHandle).cells + lDataOffset;
- gIndex = *(unsigned short*)cellDataPtr;
-
- switch (kind) {
- case kGroup:
- switch ((**gInfo).groupKind) {
- case kFullGroup:
- case kNewGroup:
- DrawFullOrNewGroupCell();
- break;
- case kUserGroup:
- DrawUserGroupCell();
- break;
- }
- break;
- case kSubject:
- DrawSubjectCell();
- break;
- }
-
- if (selected) HiliteCell();
- }
-
-
-
- /*----------------------------------------------------------------------------
- ldef_InitUPP
-
- Initialize UPPs.
- ----------------------------------------------------------------------------*/
-
- void ldef_InitUPP (void)
- {
- gListDefFuncUPP = NewListDefProc(ListDefFunc);
- }
-